var a = getApp();
Page({
  data: {
    arr: [],
    movies: [
      // {
      //   url: '../../images/Rotating/3.jpg'
      // },
      // {
      //   url: '../../images/Rotating/news.png'
      // },
      // {
      //   url: '../../images/Rotating/1.jpg'
      // },
      // {
      //   url: '../../images/Rotating/2.jpg'
      // }
    ],
  },
  getTopBanner: function getTopBanner() {
    var _this = this;
    wx.cloud.database().collection("lunbotu").get().then(function (res) {
      console.log("首页banner成功", res.data);
      if (res.data && res.data.length > 0) {
        // 如果后台配置轮播图就用后台的，没有的话就用默认的
        _this.setData({
          movies: res.data
        });
      }
    }).catch(function (res) {
      console.log("首页banner失败", res);
    });
  },

 async onLoad() {
    var that = this;
    const db = wx.cloud.database({ // 链接数据表
      env: "tangtang-0gijvqhs3851baf6"
    });
    await db.collection('switch').where({}).get({
      success: function (res) {
        console.log("成功")
        that.setData({
          switch:res.data[0].switch
        })
      },
      fail:function(res){
        console.log("switch失败")
      }
    })
    await db.collection('announcement').where({}).get({
      success: function (res) {
        let all = []
        // res.data 包含该记录的数据
        for (let i = 0; i < 3; i++) {
          all.push(res.data[i])
        }
        that.setData({
          arr: all,
        })
      }
    })
    this.getTopBanner();
  },

  navigator() {
    wx.reLaunch({
      url: "../hall/hall"
    })
  },

})